Skip to content

Error: Don't persist redundant filePath value - #4751

Closed
staabm wants to merge 2 commits into
phpstan:2.1.xfrom
staabm:less-result
Closed

staabm wants to merge 2 commits into
phpstan:2.1.xfrom
staabm:less-result

Conversation

@staabm

@staabm staabm commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor

Most errors in the resultCache.php contain the same path and filePath, see e.g.

...
\PHPStan\Analyser\Error::__set_state(array(
       'message' => 'Doing instanceof PHPStan\\Type\\FloatType is error-prone and deprecated. Use Type::isFloat() instead.',
       'file' => '/Users/m.staab/dvl/phpstan-src/src/Type/Generic/TemplateTypeFactory.php',
       'line' => 82,
       'canBeIgnored' => true,
       'filePath' => '/Users/m.staab/dvl/phpstan-src/src/Type/Generic/TemplateTypeFactory.php',
       'traitFilePath' => NULL,
       'tip' => 'Learn more: <fg=cyan>https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated</>',
       'nodeLine' => 82,
       'nodeType' => 'PhpParser\\Node\\Expr\\Instanceof_',
       'identifier' => 'phpstanApi.instanceofType',
       'metadata' => 
      array (
      ),
       'fixedErrorDiff' => NULL,
    )),
...

since we already have a fallback logic like

	public function getFilePath(): string
	{
		if ($this->filePath === null) {
			return $this->file;
		}

		return $this->filePath;
	}

we can just assign null to filePath and save 1% of result-cache size

@staabm staabm closed this Jan 19, 2026
@staabm
staabm deleted the less-result branch January 19, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant